<template>
	<view class="orders">
		<view class="tables">
			<u-tabs-swiper ref="tabs" :list="list" :is-scroll="false" :current="status" active-color="#FC5E14"
				@change="tabsChange">
			</u-tabs-swiper>
		</view>
		<swiper style="height: 100%;overflow: scroll;" :current="swiperCurrent" @transition="transition"
			@animationfinish="animationfinish">
			<swiper-item class="sw" v-for="(item, index) in list" :key="index">
				<OrderInfo :status="index" :index="swiperCurrent"></OrderInfo>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import OrderInfo from '@/components/OrderInfo/OrderInfo.vue'
	import request from '@/util/request.js'
	export default {
		components: {
			OrderInfo
		},
		data() {
			return {
				swiperCurrent: 0,
				status: 0,
				list: [{
						name: '全部'
					}, {
						name: '待付款'
					}, {
						name: '待发货'

					},
					{
						name: '待收货'

					},
					{
						name: '已完成'

					},
				]
			}
		},
		methods: {
			// 获取用户信息
			getUserInfo() {
				request.globalRequest({
					url: "/api/member/user/info"
				}).then(res => {
					console.log(res);
					if (res.status == "login") {
						uni.redirectTo({
							url: "/pages/login/login"
						})
					}

				})
			},
			tabsChange(index) {
				this.swiperCurrent = index;
			},
			// swiper-item左右移动，通知tabs的滑块跟随移动
			transition(e) {
				let dx = e.detail.dx;
				this.$refs.tabs.setDx(dx);
			},
			// 由于swiper的内部机制问题，快速切换swiper不会触发dx的连续变化，需要在结束时重置状态
			// swiper滑动结束，分别设置tabs和swiper的状态
			animationfinish(e) {
				let current = e.detail.current;
				this.$refs.tabs.setFinishCurrent(current);
				this.swiperCurrent = current;
				this.status = current;
			},
		},
		onLoad() {
			const routes = getCurrentPages()
			this.status = parseInt(routes[0].$route.query.status)
		},
		created() {
			this.getUserInfo()
		}
	}
</script>

<style lang="scss" scoped>
	.orders {
		height: 623px;
		padding-top: 60rpx;

		.tables {
			position: fixed;
			top: 88rpx;
			left: 0;
			background-color: #fff;
			z-index: 9999;
			width: 100%;
		}

	}
</style>
